#include "sendqueue.h"
#include <QDebug>
SendQueue* SendQueue::sendqueue=nullptr;

SendQueue::SendQueue()
{
    queue=new QQueue<QPair<QPair<QString,QString>,QString>>();
    isSending=false;
}

SendQueue *SendQueue::getInstance()
{
    if(sendqueue==nullptr){
        sendqueue=new SendQueue();
    }
    return sendqueue;
}

void SendQueue::addFile(QString senderoc, QString receiver, QString filepath)
{
    QPair<QPair<QString,QString>,QString> tmp=QPair<QPair<QString,QString>,QString>(QPair<QString,QString>(senderoc,receiver),filepath);
    queue->enqueue(tmp);
    if(!isSending)
    {
        emit s_haveNewTask();
        isSending=true;
    }
}

QPair<QPair<QString, QString>, QString> SendQueue::getTask()
{
    if(queue->isEmpty())return QPair<QPair<QString, QString>, QString>();
    return queue->dequeue();
}

void SendQueue::checkQueue()
{
    isSending=false;
    if(!queue->isEmpty())
    {
        isSending=true;
        emit s_haveNewTask();
    }
    emit s_doneWork();
}

bool SendQueue::isEmpty()
{
    return queue->isEmpty();
}
